#include "RenderObject.h"

namespace Nezha
{

	RenderObject::RenderObject()
		:mRenderLayer(RL_DEFAULT)
		,mBatchType(ROB_NONE)
	{

	}

	MaterialPtr RenderObject::getMaterial(u32 i)
	{
		NZ_ASSERT(i < mMatLayers.size());

		return mMatLayers[i];
	}

	void RenderObject::setMaterial(u32 i, const MaterialPtr& mat)
	{
		NZ_ASSERT(i < mMatLayers.size());

		mMatLayers[i] = mat;
	}

	void RenderObject::prepareGeometry4Pipeline(GeometryDataBatch& batch)
	{
		if(mRenderMeshPtr.isNull() || !mRenderMeshPtr->getDataRaw())
		{
			batch.clear();
		}
		else
		{
			GeometryData* gd = mRenderMeshPtr->getDataRaw();
			u32 numVerts = gd->getNumVertex();
			u32 numIndices = gd->getNumIndices();

			batch.createBatch(0, 0, numVerts, numIndices, GeometryDataPtr(gd));
		}
	}

	u32 RenderObject::getGeometryHash()
	{
		if(!mRenderMeshPtr.isNull())
		{
			return (u32)mRenderMeshPtr->getDataRaw();
		}

		return 0;
	}

}//end namespace Nezha